package com.bocloud.cmp.dao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.bocloud.cmp.dao.ServerIpDao;
import com.bocloud.cmp.entity.resource.ServerIp;
import com.bocloud.common.model.Param;
import com.bocloud.common.utils.Common;
import com.bocloud.common.utils.MapTools;
import com.bocloud.database.core.BasicDao;

@Repository("serverIpDao")
public class ServerIpDaoImpl extends BasicDao implements ServerIpDao {

    @Override
    public List<ServerIp> list(int page, int rows, List<Param> params, Map<String, String> sorter) throws Exception {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public List<ServerIp> querybyuuid(String uuid) throws Exception {
        String sql = "select * from server_ip where uuid = :uuid";
        Map<String, Object> params = MapTools.simpleMap(Common.UUID, uuid);
        List<Object> list = this.queryForList(sql, params, ServerIp.class);
        if (list.isEmpty()) {
            return null;
        }
        List<ServerIp> serverIps = new ArrayList<>();
        ServerIp serverip = null;
        for (Object obj : list) {
            serverip = (ServerIp) obj;
            serverIps.add(serverip);
        }
        return serverIps;
    }

    @Override
    public ServerIp save(ServerIp entity) throws Exception {
        return (ServerIp) this.saveEntity(entity);
    }

    @Override
    public boolean update(ServerIp entity) throws Exception {
        return this.updateEntity(entity);
    }

    @Override
    public boolean remove(Long id) throws Exception {
        String sql = "delete from server_ip where id = :id";
        Map<String, Object> params = MapTools.simpleMap(Common.ID, id);
        return this.update(sql, params) > 0;
    }

    @Override
    public boolean removebyuuid(String uuid) throws Exception {
        String sql = "delete from server_ip where uuid = :uuid";
        Map<String, Object> params = MapTools.simpleMap(Common.UUID, uuid);
        return this.update(sql, params) > 0;
    }

}
